<style>
    .layui-form-item .layui-input-company {
        width: auto;
        padding-right: 10px;
        line-height: 38px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
		<form class="layui-form layui-form-pane" action="" id="passForm">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="oldPass" lay-verify="required|oldPass" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码" value="" class="layui-input">
                    <tip>填写自己账号的旧密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="required" lay-reqtext="新密码不能为空" placeholder="请输入新的密码" value="" class="layui-input">
                    <tip>填写自己账号的新密码。</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="againPass" lay-verify="required|againPass" lay-reqtext="请再次输入新的密码不能为空" placeholder="请再次输入新的密码" value="" class="layui-input">
                     <tip>再次填写自己账号的新密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form', 'miniPage'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            miniPage = layui.miniPage;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        
		//校验输入
		form.verify({
                againPass: function (value, item) {
                	//var fd=form.val('passForm') 
                	
		        	if ($('input[name=password]').val()!=value){
		            	return "两次输入的新密码不一致";       
		        	}
                }, 
 				oldPass: function (value) {
	        		var isOld=true;       
		         	$.ajax({
						url: "/user/is_old/"+value,
						type: 'get',
						async: false,
						dataType: 'json',
						success: function(data) {
							if (data.code!=0){
								isOld=false
							}
						}
					});
					if (!isOld)
				 		return "用户旧密码不正确";
                }
 		 })
 		 
         //监听提交
        form.on('submit(saveBtn)', function (data) {
        	$.ajax({
				url: "/user/ower_pass/"+data.field.password,
				type: 'get',
				async: false,
				dataType: 'json',
				success: function(data) {
					var msg="修改用户密码成功";
					if (data.code!=0){
						msg="修改用户密码失败";
					}
			        var index = layer.alert(msg, {
		                title: '修改密码'
		            }, function () {
		                layer.close(index);
						if (data.code==0)
		                	miniPage.hashHome();//转到主页
		            });
				}
			});
            return false;
        });

    });
</script>